This page last changed on Nov 07, 2006 by ross.

The file connector allows files to be read and written to and from directories on the local file system. The connector can be configured to filter the file it reads and the way files are written, such as whether binary output is used or the file is appended to.

The javadoc for this transport provider can be found here . And the Source Xref can be found here .

File Connector Properties

Property Description Default Required
moveToDirectory The directory path where the file should be written once it has been read. if this is not set the file read is deleted.   No
writeToDirectory The directory path where the file should be written on dispatch. This path is usually set as the endpoint of the dispatch event, however this allows you to explicitly force a single directory for the connector.   No
pollingFrequency The frequency in milliseconds that the read directory should be checked. Not the read directory is specified by the endpoint of the listening component. 1000 Yes
filenameParser Is an implementation of org.mule.providers.file.FilenameParser and is used to control how filename patterns are used to generate file names. The file provider has a default implementation called org.mule.providers.file.SimpleFilenameParser that understands the following patterns:
  • ${DATE} - the current date in the format dd-MM-yy_HH-mm-ss.SS
  • ${DATE:yy-MM-dd} - the current date using the specified format
  • ${SYSTIME} - The current system time milliseconds
  • ${UUID} - A generated Universally unique id
  • ${ORIGINALNAME} - The original file name if the file being written was read from another location
  • ${COUNT} - An incremental counter
org.mule.providers.file. SimpleFilenameParser Yes
outputPattern The pattern to use when writing a file to disk. This can use the patterns supported by the filenameParser configured for this connector ${DATE} (If default is used) Yes
moveToPattern The pattern to use when moving a read file to an new location determined by the moveToDirectory property. This can use the patterns supported by the filenameParser configured for this connector ${DATE} (If default is used) Yes
outputAppend Determines whether the file being written should append to an existing file if one exists. false No
serialiseObjects Determines whether objects should be serialized to the file or not. If not the raw bytes or text is written. false No
binary Determines if the connector is reading or writing binary files false No
autoDelete By default, when a file is received it is read into a String or byte[]. The file is moved if the moveToDirectory is set, otherwise it is deleted. To access the File object set this property to false and specify a NoActionTransformer transformer for the connector. Mule will not delete the file, so it's up to the component to delete it when it's done. If the moveToDirectory is set, the file is first moved, then the File object of the moved file is passed to the component. It is recommended that a moveToDirectory is specified when turning autoDelete off. true No

File Endpoints

File endpoints are expressed using standard File URI syntax -

file://<path>[?params]

For example, to connect to a directory called /temp/files -

Unix

file:///temp/files

Note the extra slash to denote a path from the root (absolute path).

Windows

file:///C:/temp/files

The Unix style will still work in Windows if you map to a single drive (the one Mule was started from).

To specify a relative path use -

file://./temp

or
file://temp (note only 2 slashes for protocol, so it's a relative path, the above syntax is preferred for readability) 

or

file://?address=./temp

Windows network URIs
To connect to a windows network drive use -

file:////192.168.0.1/temp/

Filename Filters

Filters can be set on the endpoint to control what files are received by the endpoint. The filters are expressed in a comma-separated list. To set up a filter to only read .xml and .txt files the following can be used.

<endpoint address="file:///inbound/myfiles">
    <filter pattern="*.txt,*.xml"
         className="org.mule.providers.file.filters.FilenameWildcardFilter"/>
</endpoint>

Property Overrides

You can override certain properties when defining a File receiver endpoint to control the way that particular receiver behaves. the properties that can be set on the individual endpoint are moveToDirectory, moveToPattern, pollingFrequency and autoDelete.

<endpoint address="file:/./temp/myfiles">
    <properties>
        <property name="pollingFrequency" value="30000"/>
        <property name="moveToDirectory" value="./temp/myfiles/done"/>
    </properties>
</endpoint>

Or to specify the same Endpoint using an URI -

file:/./temp/myfiles?pollingFrequency=1000&moveToDirectory=./temp/myfiles/done


For more information about configuring Endpoint go here.

Transformers

Transformers for the File provider can be found at org.mule.providers.file.transformers.

Transformer Description
FileToByteArray
Reads the contents of a file as a byte array
FileToString
Reads a file's contents into a string.

The FileToByteArray is used if no other transformers are specified. It could also return the byte array as a String if the component request it.

Document generated by Confluence on Nov 27, 2006 10:27